<template>
  <main class="pug-pro-basicLayout-content pug-pro-basicLayout-has-header">
    <div class="pug-pro-page-container">
      <div class="pug-pro-page-container-warp">
        <div class="pug-page-header has-breadcrumb">
          <div class="pug-page-header-heading">
            <div class="pug-page-header-heading-left">
              <span class="pug-page-header-heading-title" title="分步表单">{{ opid ? '修改产品' : "添加产品" }}</span>
              编辑的id是:{{ opid }}
            </div>
          </div>
          <div class="pug-page-header-content">
            <div class="pug-pro-page-container-detail">
              <div class="pug-pro-page-container-main">
                <div class="pug-pro-page-container-row">
                  <div class="pug-pro-page-container-content">
                    视频模块页用于向用户收集或验证信息，分步视频模块常见于数据项较多的表单场景。
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="pug-pro-grid-content">
        <div class="pug-pro-grid-content-children">
          <div class="pug-pro-layout-watermark-wrapper" style="position: relative;">
            <div class="pug-pro-page-container-children-content">
              <div class="pug-card">
                <div class="pug-pro-steps-form-steps-container" style="max-width: 760px;padding: 20px 0">
                  <div class="pug-steps pug-steps-horizontal pug-steps-label-horizontal">
                    <div class="pug-steps-item" @click="next(1)"
                         :class="[currentStep>=1?'pug-steps-item-process pug-steps-item-active':'']">
                      <div class="pug-steps-item-container">
                        <div class="pug-steps-item-tail"></div>
                        <div class="pug-steps-item-icon"><span class="pug-steps-icon">1</span></div>
                        <div class="pug-steps-item-content">
                          <div class="pug-steps-item-title">基本信息</div>
                        </div>
                      </div>
                    </div>
                    <div class="pug-steps-item pug-steps-item-wait" @click="next(2)"
                         :class="[currentStep>=2?'pug-steps-item-process pug-steps-item-active':'']">
                      <div class="pug-steps-item-container">
                        <div class="pug-steps-item-tail"></div>
                        <div class="pug-steps-item-icon"><span class="pug-steps-icon">2</span></div>
                        <div class="pug-steps-item-content">
                          <div class="pug-steps-item-title">明细控制</div>
                        </div>
                      </div>
                    </div>
                    <div class="pug-steps-item pug-steps-item-wait" @click="next(3)"
                         :class="[currentStep>=3?'pug-steps-item-process pug-steps-item-active':'']">
                      <div class="pug-steps-item-container">
                        <div class="pug-steps-item-tail"></div>
                        <div class="pug-steps-item-icon"><span class="pug-steps-icon">3</span></div>
                        <div class="pug-steps-item-content">
                          <div class="pug-steps-item-title">价格控制</div>
                        </div>
                      </div>
                    </div>
                    <div class="pug-steps-item pug-steps-item-wait" @click="next(4)"
                         :class="[currentStep>=4?'pug-steps-item-process pug-steps-item-active':'']">
                      <div class="pug-steps-item-container">
                        <div class="pug-steps-item-tail"></div>
                        <div class="pug-steps-item-icon"><span class="pug-steps-icon">4</span></div>
                        <div class="pug-steps-item-content">
                          <div class="pug-steps-item-title">产品描述</div>
                        </div>
                      </div>
                    </div>
                    <div class="pug-steps-item pug-steps-item-wait" @click="next(5)"
                         :class="[currentStep>=5?'pug-steps-item-process pug-steps-item-active':'']">
                      <div class="pug-steps-item-container">
                        <div class="pug-steps-item-tail"></div>
                        <div class="pug-steps-item-icon"><span class="pug-steps-icon">5</span></div>
                        <div class="pug-steps-item-content">
                          <div class="pug-steps-item-title">发布完成</div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <div v-show="currentStep==1" class="pug-card mt20">
                <div class="pug-card-body">
                  <div class="pug-debug-result">{{uservideo}}</div>
                  <div class="pug-row" style="justify-content: center">

                    <div class="pug-col pug-col-lg-8" style="padding:0 30px;">
                      <div autocomplete="off" class="pug-form pug-form-vertical pug-form-hide-required-mark">
                         <input type="hidden" v-model="uservideo.id" cref="id"/>
                         <div class="pug-row pug-form-item" style="row-gap: 0px;">
                          <div class="pug-col pug-form-item-label">
                             <label class="pug-form-item-required" title="视频链接图片">视频链接图片
                                <span class='pug-valid-label'>(*必填)</span>
                             </label>
                          </div>
                          <div class="pug-col pug-form-item-control">
                            <div class="pug-col   pug-col-lg-3" style="padding-left: 8px; padding-right: 8px;">
                              <pug-upload @callback="uploadSuccess" modal="2" cref="urlLinkImg" uploadname="urlLinkImg"
                                          v-model="uservideo.urlLinkImg" :key="timer"></pug-upload>
                              <div style="display: none;">
                                <pug-input placeholder="请上传视频链接的图片" cref="urlLinkImg" v-model="uservideo.urlLinkImg" type="text"></pug-input>
                              </div>
                            </div>
                          </div>
                        </div>
                         <div class="pug-row pug-form-item" style="row-gap: 0px;">
                          <div class="pug-col pug-form-item-label">
                             <label class="pug-form-item-required" title="视频链接标题">视频链接标题
                                <span class='pug-valid-label'>(*必填)</span>
                             </label>
                          </div>
                          <div class="pug-col pug-form-item-control">
                            <div class="pug-form-item-control-input">
                             <div class="pug-form-item-control-input-content">
                                 <pug-input  placeholder="请输入视频链接标题" cref="urlLinkTitle" maxlen="200"  v-model="uservideo.urlLinkTitle" type="text"></pug-input>
                            </div>
                            </div>
                          </div>
                        </div>
                         <div class="pug-row pug-form-item" style="row-gap: 0px;">
                          <div class="pug-col pug-form-item-label">
                             <label class="pug-form-item-required" title="视频标题">视频标题
                             </label>
                          </div>
                          <div class="pug-col pug-form-item-control">
                            <div class="pug-form-item-control-input">
                             <div class="pug-form-item-control-input-content">
                                 <pug-input  placeholder="请输入视频标题" cref="videoTile" maxlen="100"  v-model="uservideo.videoTile" type="text"></pug-input>
                            </div>
                            </div>
                          </div>
                        </div>
                         <div class="pug-row pug-form-item" style="row-gap: 0px;">
                          <div class="pug-col pug-form-item-label">
                             <label class="pug-form-item-required" title="商品描述">商品描述
                             </label>
                          </div>
                          <div class="pug-col pug-form-item-control">
                            <div class="pug-form-item-control-input">
                             <div class="pug-form-item-control-input-content">
                                 <pug-input  placeholder="请输入商品描述" cref="videoDesc" maxlen="800"  v-model="uservideo.videoDesc" type="text"></pug-input>
                            </div>
                            </div>
                          </div>
                        </div>
                         <div class="pug-row pug-form-item" style="row-gap: 0px;">
                          <div class="pug-col pug-form-item-label">
                             <label class="pug-form-item-required" title="用户id">用户id
                             </label>
                          </div>
                          <div class="pug-col pug-form-item-control">
                            <div class="pug-form-item-control-input">
                             <div class="pug-form-item-control-input-content">
                                 <pug-input  placeholder="请输入用户id" cref="userId" maxlen="20"  v-model="uservideo.userId" type="text"></pug-input>
                            </div>
                            </div>
                          </div>
                        </div>
                         <div class="pug-row pug-form-item" style="row-gap: 0px;">
                          <div class="pug-col pug-form-item-label">
                             <label class="pug-form-item-required" title="用户昵称">用户昵称
                                <span class='pug-valid-label'>(*必填)</span>
                             </label>
                          </div>
                          <div class="pug-col pug-form-item-control">
                            <div class="pug-form-item-control-input">
                             <div class="pug-form-item-control-input-content">
                                 <pug-input  placeholder="请输入用户昵称" cref="userNickname" maxlen="100"  v-model="uservideo.userNickname" type="text"></pug-input>
                            </div>
                            </div>
                          </div>
                        </div>
                         <div class="pug-row pug-form-item" style="row-gap: 0px;">
                          <div class="pug-col pug-form-item-label">
                             <label class="pug-form-item-required" title="用户头像">用户头像
                             </label>
                          </div>
                          <div class="pug-col pug-form-item-control">
                            <div class="pug-form-item-control-input">
                             <div class="pug-form-item-control-input-content">
                                 <pug-input  placeholder="请输入用户头像" cref="userAvatar" maxlen="200"  v-model="uservideo.userAvatar" type="text"></pug-input>
                            </div>
                            </div>
                          </div>
                        </div>
                         <div class="pug-row pug-form-item" style="row-gap: 0px;">
                          <div class="pug-col pug-form-item-label">
                             <label class="pug-form-item-required" title="视频地址">视频地址
                             </label>
                          </div>
                          <div class="pug-col pug-form-item-control">
                            <div class="pug-form-item-control-input">
                             <div class="pug-form-item-control-input-content">
                               <video
                                 ref="videoPlay"
                                 :src="uservideo.videoPath"
                                 width="500"
                                 height="500"
                                 style="background-color: #eeeeee"
                                 controls="controls"
                               >
                                 您的浏览器不支持视频播放
                               </video>
                            </div>
                            </div>
                          </div>
                        </div>
                         <div class="pug-row pug-form-item" style="row-gap: 0px;">
                          <div class="pug-col pug-form-item-label">
                             <label class="pug-form-item-required" title="视频跳转到酒店">视频跳转到酒店
                             </label>
                          </div>
                          <div class="pug-col pug-form-item-control">
                            <div class="pug-form-item-control-input">
                             <div class="pug-form-item-control-input-content">
                                 <pug-input  placeholder="请输入视频跳转到酒店" cref="hotelLink" maxlen="200"  v-model="uservideo.hotelLink" type="text"></pug-input>
                            </div>
                            </div>
                          </div>
                        </div>
                         <div class="pug-row pug-form-item" style="row-gap: 0px;">
                          <div class="pug-col pug-form-item-label">
                             <label class="pug-form-item-required" title="发布状态">发布状态
                             </label>
                          </div>
                          <div class="pug-col pug-form-item-control">
                            <div class="pug-form-item-control-input">
                             <div class="pug-form-item-control-input-content">
                              <pug-radio v-model="uservideo.status" cref="status" :items='[{text:"是",value:1},{text:"否",value:0}]' :is-value="false"></pug-radio>
                            </div>
                            </div>
                          </div>
                        </div>
                         <div class="pug-row pug-form-item" style="row-gap: 0px;">
                          <div class="pug-col pug-form-item-label">
                             <label class="pug-form-item-required" title="排序字段">排序字段
                                <span class='pug-valid-label'>(*必填)</span>
                             </label>
                          </div>
                          <div class="pug-col pug-form-item-control">
                            <div class="pug-form-item-control-input">
                             <div class="pug-form-item-control-input-content">
                                 <pug-input  placeholder="请输入排序字段" cref="sorted" maxlen="11"  v-model="uservideo.sorted" type="text"></pug-input>
                            </div>
                            </div>
                          </div>
                        </div>
                         <div class="pug-row pug-form-item" style="row-gap: 0px;">
                          <div class="pug-col pug-form-item-label">
                             <label class="pug-form-item-required" title="酒店id">酒店id
                             </label>
                          </div>
                          <div class="pug-col pug-form-item-control">
                            <div class="pug-form-item-control-input">
                             <div class="pug-form-item-control-input-content">
                                 <pug-input  placeholder="请输入酒店id" cref="hotelId" maxlen="20"  v-model="uservideo.hotelId" type="text"></pug-input>
                            </div>
                            </div>
                          </div>
                        </div>
                         <div class="pug-row pug-form-item" style="row-gap: 0px;">
                          <div class="pug-col pug-form-item-label">
                             <label class="pug-form-item-required" title="删除状态">删除状态
                             </label>
                          </div>
                          <div class="pug-col pug-form-item-control">
                            <div class="pug-form-item-control-input">
                             <div class="pug-form-item-control-input-content">
                              <pug-radio v-model="uservideo.isdelete" cref="isdelete" :items='[{text:"不删除",value:0},{text:"删除",value:1}]' :is-value="false"></pug-radio>
                            </div>
                            </div>
                          </div>
                        </div>
                        <!--保存和下一步按钮-->
                        <div class="pug-space pug-space-horizontal pug-space-align-center"
                             style="flex-wrap: wrap; gap: 8px;">
                          <div class="pug-space-item" style="">
                             <router-link to="/uservideo"><button  class="pug-btn pug-btn-primary mr10"><span><i class="iconfont icon-icon_arrow_left pr3 fz13"></i>返回</span></button></router-link>
                             <button type="button" v-if="!uservideo.id" class="pug-btn pug-btn-primary mr3" @click="saveorupdate()"><span><i class="iconfont icon-tianjia pr3"></i>保存</span></button>
                             <button type="button" v-if="uservideo.id" class="pug-btn pug-btn-primary mr3" @click="saveorupdate()"><span><i class="iconfont icon-quanbudingdan pr3"></i>编辑</span></button>
                           </div>
                          <div class="pug-space-item" style="">
                            <button type="button" class="pug-btn" @click="next(2)"><span>下一步</span>
                            </button>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
             <div v-show="currentStep==2" class="pug-card mt20">
              2
             </div>
             <div v-show="currentStep==3" class="pug-card mt20">
              3
             </div>
             <div v-show="currentStep==4" class="pug-card mt20">
              4
             </div>
             <div v-show="currentStep==5" class="pug-card mt20">
               5
             </div>
         </div>
       </div>
     </div>
   </div>
 </div>
</main>
</template>
<script>
import uservideoService from '@/services/uservideo'
import pugDialog from "@/plugins/PugDialog";
import pugMessage from "@/plugins/PugMessage";
import {isEmpty,getById,isNotEmpty} from "@/utils/validate";
import cache from "@/utils/cache"
export default {
  name: "UserVideoAdd.vue",
  components: {},
  data() {
    return {
      opid: "",
      uservideo:{
        id:"", // 视频表主键
        urlLinkImg:"", // 视频链接图片
        urlLinkTitle:"", // 视频链接标题
        videoTile:"", // 视频标题
        videoDesc:"", // 商品描述
        userId:"", // 用户id
        userNickname:"", // 用户昵称
        userAvatar:"", // 用户头像
        videoPath:"", // 视频地址
        hotelLink:"", // 视频跳转到酒店
        status:1 , // 发布状态
        sorted:1 , // 排序字段
        hotelId:"", // 酒店id
        isdelete:0  // 删除状态
      },

      currentStep: 1,
      steps: [1, 2, 3]
    }
  },

  created() {

    // 根据id视频模块明细
    if(!isEmpty(this.$route.params.id)){
      this.uservideo.id = this.$route.params.id;
      this.opid = this.$route.params.id;
      // 加载明细
      this.getDetail();
    }else{
      if(isNotEmpty(cache.local.get("uservideo_save"))) {
        this.uservideo = cache.local.getJSON("uservideo_save")
      }
    }
  },

   watch:{
      uservideo:{
        deep:true,
        handler(val){
          cache.local.setJSON("uservideo_save",val);
        }
      }
   },

  methods: {

    // 加载明细
    async getDetail(){
      try{
        const res = await  uservideoService.getUserVideo(this.opid);
        this.uservideo = res.data;
      }catch (err) {
        pugMessage.error("服务器异常,代号：1025");
      }
    },

    // 1: 保存方法
    async saveorupdate() {
        try{
            // 校验
            const vresult = await this.validator();
            if(!vresult){
                return;
            }

            pugDialog.confirm('提示',"你确定进行【"+(this.uservideo.id?'更新':'保存')+"】吗？").then(async ()=>{
                // 执行服务器数据保存视频模块
                const res = await  uservideoService.saveUpdateUserVideo(this.uservideo);
                if(res.status == 200){
                    if(isEmpty(this.uservideo.id)){
                        // 重置数据
                        this.reset();
                        cache.local.remove("uservideo_save");
                        // 返回列表
                        pugMessage.success("添加成功");
                        this.$router.push("/uservideo/list");
                    }else{
                        cache.local.remove("uservideo_save");
                        // 返回列表
                        pugMessage.success("修改成功");
                        this.$router.push("/uservideo/list");
                    }
                }
            })
        }catch(err){
            pugMessage.error("服务器异常,代号：1025");
        }
    },

    // 2: 校验
    async validator(){

        if(isEmpty(this.uservideo.urlLinkImg)){
           pugMessage.error("请输入视频链接图片");
           getById('urlLinkImg').focus();
           return false;
        }

        if(isEmpty(this.uservideo.urlLinkTitle)){
           pugMessage.error("请输入视频链接标题");
           getById('urlLinkTitle').focus();
           return false;
        }

        if(isEmpty(this.uservideo.videoTile)){
           pugMessage.error("请输入视频标题");
           getById('videoTile').focus();
           return false;
        }

        if(isEmpty(this.uservideo.videoDesc)){
           pugMessage.error("请输入商品描述");
           getById('videoDesc').focus();
           return false;
        }

        if(isEmpty(this.uservideo.userId)){
           pugMessage.error("请输入用户id");
           getById('userId').focus();
           return false;
        }

        if(isEmpty(this.uservideo.userNickname)){
           pugMessage.error("请输入用户昵称");
           getById('userNickname').focus();
           return false;
        }

        if(isEmpty(this.uservideo.userAvatar)){
           pugMessage.error("请输入用户头像");
           getById('userAvatar').focus();
           return false;
        }

        if(isEmpty(this.uservideo.videoPath)){
           pugMessage.error("请输入视频地址");
           getById('videoPath').focus();
           return false;
        }

        if(isEmpty(this.uservideo.hotelLink)){
           pugMessage.error("请输入视频跳转到酒店");
           getById('hotelLink').focus();
           return false;
        }

        if(isEmpty(this.uservideo.status)){
           pugMessage.error("请输入发布状态");
           getById('status').focus();
           return false;
        }

        if(isEmpty(this.uservideo.sorted)){
           pugMessage.error("请输入排序字段");
           getById('sorted').focus();
           return false;
        }

        if(isEmpty(this.uservideo.hotelId)){
           pugMessage.error("请输入酒店id");
           getById('hotelId').focus();
           return false;
        }

        if(isEmpty(this.uservideo.isdelete)){
           pugMessage.error("请输入删除状态");
           getById('isdelete').focus();
           return false;
        }

        return true;
    },

    // 3: 步骤分解
    prev(index) {
      this.currentStep = index;
    },

    next(index) {
      this.currentStep = index;
    },

    // 4: 文件上传回调
    uploadSuccess(response) {
      this.uservideo.urlLinkImg = response.url;
      console.log("uploadSuccess:", response)
    },

    // 5: 重置数据
    reset(){
        this.uservideo = {
         citems: [{text:"请选择",value:""}],
         id:"", // 视频表主键
         urlLinkImg:"", // 视频链接图片
         urlLinkTitle:"", // 视频链接标题
         videoTile:"", // 视频标题
         videoDesc:"", // 商品描述
         userId:"", // 用户id
         userNickname:"", // 用户昵称
         userAvatar:"", // 用户头像
         videoPath:"", // 视频地址
         hotelLink:"", // 视频跳转到酒店
         status:"", // 发布状态
         sorted:"", // 排序字段
         hotelId:"", // 酒店id
         isdelete:"" // 删除状态
       }
    },


  }
}
</script>
<style scoped="">
</style>
